<template>
    <div style="height:100%;">
        <vue-better-scroll class="wrapper"
                           ref="scroll"
                           :scrollbar="scrollbarObj"
                           :pullDownRefresh="pullDownRefreshObj"
                           :pullUpLoad="pullUpLoadObj"
                           :startY="parseInt(startY)"
                           @pullingUp="onPullingUp">
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>开始时间</label>
                </div>
                <group>
                    <datetime v-model="BeginDate"></datetime>
                </group>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>结束时间</label>
                </div>
                <group>
                    <datetime v-model="EndDate"></datetime>
                </group>
            </div>
            <div class="btns">
                <button data-v-7e6e7efa=""
                        class="green width200"
                        @click="getData">查询</button>
            </div>
            <div class="cut-off-rule"></div>
            <ul class="lists">
                <li v-for="(item,index) in list"
                    :key="index">
                    <router-link :to="{path:'/view3Details2',query:{
                  id:item.Id
                }}">
                        <div>
                            <h5>{{item.EquipmentTypeName}}{{item.EquipmentNo}}</h5>
                            <p>{{item.Category}}</p>
                            <p>项目层级({{item.CheckType}})</p>
                        </div>
                        <div class="status">
                            <span class="blue">{{item.CheckDate}}</span>
                            <x-icon type="ios-arrow-right"
                                    size="20"
                                    class="icon-right"></x-icon>
                        </div>
                    </router-link>
                </li>
            </ul>
            <noData v-if="list.length == 0"></noData>
        </vue-better-scroll>
        <myMenu></myMenu>
    </div>
</template>
<script>
import VueBetterScroll from 'vue2-better-scroll'
import formatDate from '@/utils/formatDate'
import myMenu from '@/commonComponents/menu'
export default {
    name: 'inspectionRecord',
    data () {
        return {
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: false,
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            BeginDate: `${formatDate().split('-')[0]}-01-01`,
            EndDate: formatDate(),
            userInfo: '',
            list: [],
            pageIndex: 0, // 当前页
            listAllCount: 0 // 总条数
        }
    },
    components: {
        VueBetterScroll,
        myMenu
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.getList()
    },
    methods: {
        getData () {
            this.pageIndex = 0
            this.list = []
            this.getList()
        },
        onPullingUp () {
            this.pageIndex++
            this.getList()
        },
        getList () {
            this.$vux.loading.show({
                text: '加载中...'
            })
            let params = {
                'allowPaging': true,
                'business': 'GetEquipmentCheckWork',
                'data': {
                    id: this.$route.query.Id,
                    BeginDate: this.BeginDate,
                    EndDate: this.EndDate

                },
                'pageIndex': this.pageIndex,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.listAllCount = res.data.count
                    this.list = this.list.concat(res.data.data)
                    if (this.list.length < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        }
    }
}
</script>
<style lang="less" scoped>
.lists {
    padding-left: 20px;
    a {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 14px 20px 14px 0;
        border-bottom: 1px solid #efeff4;
    }
    h5 {
        line-height: 18px;
        color: #333;
        font-size: 13px;
        font-weight: 700;
    }
    p {
        font-size: 13px;
        color: #666;
        line-height: 18px;
    }
    .status {
        display: flex;
        align-items: center;
        span {
            font-size: 12px;
        }
    }
}
</style>
